home *** CD-ROM | disk | FTP | other *** search
/ Super PC 34 / Super PC 34 (Shareware).iso / spc / UTIL / DJGPP2 / V2 / DJTST200.ZIP / tests / libc / crt0 / pagetest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-07  |  998 b   |  55 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <pc.h>
  4. #include <unistd.h>
  5.  
  6. int
  7. main(int argc, char **argv)
  8. {
  9.   unsigned long pmax, p, cs, i;
  10.   unsigned long *pp, *pbase;
  11.  
  12.   if (argc < 2)
  13.   {
  14.     printf("pagetest {kb}\n");
  15.     return 1;
  16.   }
  17.  
  18.   pmax = atoi(argv[1]) / 4;
  19.   printf("%ld pages\n", pmax);
  20.  
  21.   pbase = (unsigned long *)sbrk(pmax*4096);
  22.   if ((int)pbase == -1)
  23.   {
  24.     fprintf(stderr, "sbrk failed\n");
  25.     exit(1);
  26.   }
  27.   for (p=0; p<pmax; p++)
  28.   {
  29.     printf("\rinit page %ld  ", p);
  30.     fflush(stdout);
  31.     pp = pbase + p*1024;
  32.     cs = 0;
  33.     for (i=0; i<1023; i++)
  34.     {
  35.       pp[i] = random();
  36.       cs += pp[i];
  37.     }
  38.     pp[i] = cs;
  39.   }
  40.   printf("\r                         \r");
  41.   while (!kbhit())
  42.   {
  43.     p = random() % pmax;
  44.     printf("\rpage %ld  ", p);
  45.     fflush(stdout);
  46.     pp = pbase + p*1024;
  47.     cs = 0;
  48.     for (i=0; i<1023; i++)
  49.       cs += pp[i];
  50.     if (pp[i] != cs)
  51.       printf("Bad cs!\n");
  52.   }
  53.   return 0;
  54. }
  55.